<?php

/**
 * 作者：lucas
 * 链接：
 * 邮箱：dissipator_520@qq.com
 */

/**
 * ImportModel
 *
 * @author lucas
 */

class ImportModel extends Model {

    public $_validate = array(
        array('id', 'require', '名称必须')
    );

    function getData($condition) {

        $fields='a.ID,a.Custml,a.Mdate,a.序号,a.trackno,a.Itemno,i.name name,a.Item,a.Weight,a.QTY,a.amount,a.inv,a.Rdate,a.Idate,a.Rqty,a.bgdh,a.备注';
        $sql = "SELECT ".$fields."  FROM " . c('db_prefix') . "import as a," . c('db_prefix') . "scitem as i where a.itemno=i.id ";
        $count = "SELECT count(1) c FROM " . c('db_prefix') . "import as a," . c('db_prefix') . "scitem as i where a.itemno=i.id ";
        $where = '';

        $val = array();
        // p($condition);
        if (count($condition) > 0) {
            foreach ($condition as $key => $value) {
                $where .= 'and a.'. $key . ' ' . $value[0] . ' \'%s\' ';
                 $val[] = $value[1];
            }
        }
        $page=$_POST['page']-1; $rows=$_POST['rows'];

        $order =' order by '.$_POST['sort'].' '.$_POST['order'];
        $limit=' limit '.$page.','.$rows;
       
        $count = $this->parseSql($count . $where, $val);
        $sql = $sql . $where .$order. $limit;
        
        array_push($val, ($page - 1) * $rows);
        array_push($val, $rows);
        $sql = $this->parseSql($sql, $val);
        // echo $sql;
        $rs = $this->query($count);
        $cr = $rs[0];
        return array($this->query($sql), $cr['c']);
        // $data = $Mode->where($this->condition)->page($this->page, $this->rows)->order($this->order)->select();
    }

}